import Mock from 'mockjs'

const list = []
const count = 120

for (let i = 0; i < count; i++) {
    list.push(Mock.mock({
        id: '@increment',
        'sellCount|10-100.1': 10,
        'rate|1-9.1': 5,
        shopName: '@csentence(5)'
    }))
}

export default [
    {
        url: '/api/index/shoplist',
        type: 'post',
        response: config => {
            const { page = 1, size = 10, keyword } = config.body
            const mockList = list.filter(item => { // 根据条件筛选
                if (keyword && item.keyword.indexOf(item.shopName) !== -1) return false
                return true
            })
            const pageList = mockList.filter((item,index) => index < size * page && index >= size * (page - 1))
            return ({
                total: mockList.length,
                data: pageList,
                code: 200
            })
        }
    }
]